/*
 * @Author: your name
 * @Date: 2021-10-01 18:42:07
 * @LastEditTime: 2021-10-01 20:13:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \luogu\1.6二分查找\P1768\main.cpp
 */
#include<iostream>
#include<math.h>

using namespace std;

//分数 0-1000000 学生数 0-100000 学校数 0-100000
const int stu_num = 100005;
const int cap_num = 100005;

//在寻找与该同学分数最接近的录取线,并返回差值
int getLeastDiffer(int cap_score[],int c_num,int s_score);
//快速排序
void quickSort(int array[],int low,int high);

int main(){
    //m: 学校数目 n:学生数目
    int m,n;
    //学生分数与录取线数组
    int stu_score[stu_num],cap_score[stu_num];


    cin >> m >> n;
    //数据存储在1-m和1-n,并在0储存储1的值,m+1和n+1出存储m和n的值
    for(int i=1; i<=m; i++){
        cin >> cap_score[i];
    }
    //排序
    quickSort(cap_score,1,m);

    for(int i=1; i<=n; i++){
        cin >> stu_score[i];
    }
    //在0储存储1的值,m+1存储m的值 避免考虑上下边界
    cap_score[0] = cap_score[1];
    cap_score[m+1] = cap_score[m];

    int sum = 0;
    //查找
    for(int i=1; i<=n; i++){
        int least = getLeastDiffer(cap_score,m,stu_score[i]);
        sum += least;
    }
    cout << sum;
    return 0;
}

int getLeastDiffer(int cap_score[],int c_num,int s_score)
{
    //先进行极限判断
    if(s_score <= cap_score[1]){
        //低于最低录取线
        return cap_score[1] - s_score;
    }
    if(s_score >= cap_score[c_num]){
        //高于最高录取线
        return s_score - cap_score[c_num];
    }

    int left = 1;
    int right = c_num;
    int mid = (left+right)/2; //向下取整,左开右闭
    //二分
    while(left < right){
        if(s_score <= cap_score[mid]){
            //左区间
            right = mid;
        }else{
            //右区间
            left = mid + 1;
        }
        mid = (left+right)/2;
    }

    //介于录取线之间 取较小的间距值 比较left left-1 left+1
    int num1 = abs(s_score - cap_score[left-1]);
    int num2 = abs(s_score - cap_score[left]);
    int num3 = abs(s_score - cap_score[left+1]);

    int min_num = (num1 < num2) ? num1 : num2;
    min_num = (min_num < num3) ? min_num : num3;
    return min_num;
}

void quickSort(int array[],int low,int high)
{
    if(low < high){
        //左右指针
        int left = low;
        int right = high;
        //在覆盖前先保存
        int tem = array[low];
        //将tem放到它该在的位置
        while(left < right){
            //从右往左找第一个小于tem的值
            while(left < right && array[right] >= tem){
                right--;
            }
            //将其换到左边
            if(left < right){
                array[left++] = array[right]; 
            }

            //从左往右找到第一个大于tem的值
            while(left < right && array[left] <= tem){
                left++;
            }
            //将其换到右边
            if(left < right){
                array[right--] = array[left];
            }
        }
        //left == right tem归位
        array[left] = tem;
        //递归
        quickSort(array,low,left-1);
        quickSort(array,left+1,high);
    }
}